package com.itliang.web.controller.log;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itliang.core.model.dto.log.SysOperLogQueryRequest;
import com.itliang.core.model.entity.SysOperLog;
import com.itliang.core.result.BaseResponse;
import com.itliang.core.result.ResultUtils;
import com.itliang.service.log.SysOperLogService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author : liangzhuoyuan
 */
@Api(tags = "操作日志管理接口")
@Slf4j
@RestController
@RequestMapping("/admin/log/operLog")
public class SysOperLogController {

    @Resource
    private SysOperLogService operLogService;

    /**
     * 分页获取操作日志数据列表
     *
     * @return
     */
    @GetMapping("/list/page")
    public BaseResponse<?> listEquipmentDataByPage(SysOperLogQueryRequest queryParams) {
        String title = queryParams.getTitle();
        String userAccount = queryParams.getOperName();
        QueryWrapper<SysOperLog> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.hasText(title), "title", title)
                .like(StringUtils.hasText(userAccount),"oper_name", userAccount)
                .orderByDesc("oper_time");
        long current = queryParams.getCurrent();
        long size = queryParams.getPageSize();
        Page<SysOperLog> page = operLogService.page(new Page<>(current, size), wrapper);
        return ResultUtils.success(page);
    }
}
